# !/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
===========================
@Time : 2022/7/10 0010 15:06
@Author : 测试开发工程师
@File : department_api.py
@Software: PyCharm
============================
"""

import os
from apitest.Test_frame.apis.wework import WeWork
from apitest.Test_frame.utils.utils_yaml_path import Utils


class DepartMent(WeWork):
    """
    描述接口信息，不要去做断言等
    """

    def __init__(self):
        super().__init__()
        # 拼接路径：Test_frame/config/secrets.yaml
        path = os.sep.join([Utils.get_frame_root_path(), "config/secrets.yaml"])
        # 获取 yaml 中的数据
        yaml_data = Utils.get_yaml_data(path)
        corpid = yaml_data.get("corpid").get("yinian")
        secret = yaml_data.get("secret").get("contact")
        # _env = os.getenv("test_env")
        self.BASE_URL = yaml_data.get("dev").get("BASE_URL")
        self.get_token(corpid, secret)

    def creat(self, data):
        """
        创建部门
        """
        create_url = "/department/create"
        params = {"access_token": self.access_token}
        req = {
            "method": "POST",
            "url": create_url,
            "params": params,
            "json": data
        }
        r = self.send_api(req)
        # 不确定返回结果是不是 json ，先返回 r
        return r

    def update(self, data):
        """
        更新部门
        """
        update_url = "/department/update"
        params = {"access_token": self.access_token}
        req = {
            "method": "POST",
            "url": update_url,
            "params": params,
            "json": data
        }
        r = self.send_api(req)
        return r

    def get(self, _id=None):
        """
        获取部门信息
        """
        get_list_url = "/department/list"
        params = {"access_token": self.access_token, "id": _id}
        req = {
            "method": "GET",
            "url": get_list_url,
            "params": params
        }
        r = self.send_api(req)
        return r

    def delete(self, _id):
        """
        删除部门
        """
        delete_url = "/department/delete"
        params = {"access_token": self.access_token, "id": _id}
        req = {
            "method": "GET",
            "url": delete_url,
            "params": params
        }
        r = self.send_api(req)
        return r
